package com.mt.operation.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.operation.api.service.IArticleCollectService;
import com.mt.operation.entity.ArticleCollectEntity;
import com.mt.operation.service.model.ArticleCollectServiceModel;

@Service
public class ArticleCollectServiceImpl implements IArticleCollectService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ArticleCollectServiceImpl.class);

    @Autowired
    private ArticleCollectServiceModel articleCollectServiceModel;

    public ServiceResult<ArticleCollectEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<ArticleCollectEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = articleCollectServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<Integer> findCount(Map<String, Object> params) {
        ServiceResult<Integer> result = null;
        try {
            result = articleCollectServiceModel.selectCount(params);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][findCount]：query findCount occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<ArticleCollectEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ArticleCollectEntity>> result = new ServiceResult<List<ArticleCollectEntity>>();
        try {
            result = articleCollectServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(ArticleCollectEntity articleCollectEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = articleCollectServiceModel.insert(articleCollectEntity);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdateRelate(ArticleCollectEntity articleCollectEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = articleCollectServiceModel.updateRelate(articleCollectEntity);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer collectId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = articleCollectServiceModel.deleteByPrimaryKey(collectId);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteByCustomer(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = articleCollectServiceModel.deleteByCustomer(params);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(ArticleCollectEntity articleCollectEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = articleCollectServiceModel.updateByPrimaryKeySelective(articleCollectEntity);
        } catch (Exception e) {
            LOGGER.error("[ArticleCollectServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

}
